package com.zmn.plat.services.impl.channel.workorder.picture;

import java.util.List;
import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.channel.workorder.picture.ChannelWorkOrderPicture;
import com.zmn.plat.model.entity.channel.workorder.picture.ChannelWorkOrderPictureQuery;
import com.zmn.plat.persistence.interfaces.channel.workorder.picture.ChannelWorkOrderPictureDao;
import com.zmn.plat.services.interfaces.channel.workorder.picture.ChannelWorkOrderPictureService;

/**
 * 渠道-工单照片service实现类
 *
 * @author linfeng
 * @since 2020/09/17 17:30
 */
@Service
public class ChannelWorkOrderPictureServiceImpl implements ChannelWorkOrderPictureService {

    @Resource
    ChannelWorkOrderPictureDao channelWorkOrderPictureDao;

    @Override
    public ChannelWorkOrderPicture findByKey(Integer id) {
        return channelWorkOrderPictureDao.findByKey(id);
    }

    @Override
    public Integer findMaxSort() {
        return channelWorkOrderPictureDao.findMaxSort();
    }

    @Override
    public List<ChannelWorkOrderPicture> listPageByQuery(ChannelWorkOrderPictureQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return channelWorkOrderPictureDao.listPageByQuery(query);
    }

    @Override
    public List<ChannelWorkOrderPicture> listByQuery(ChannelWorkOrderPictureQuery query) {
        return channelWorkOrderPictureDao.listByQuery(query);
    }

    @Override
    public List<ChannelWorkOrderPicture> listAll() {
        return channelWorkOrderPictureDao.listAll();
    }

    @Override
    public Integer countByQuery(ChannelWorkOrderPictureQuery query) {
        return channelWorkOrderPictureDao.countByQuery(query);
    }

    @Override
    public Integer updateSortByKey(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.updateSortByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer updateSortByKey(Integer id, Integer sort, String mcStaffName) {
        ChannelWorkOrderPicture channelWorkOrderPicture = new ChannelWorkOrderPicture();
        channelWorkOrderPicture.setRelateId(id);
        channelWorkOrderPicture.setSort(sort);
        channelWorkOrderPicture.setUpdater(mcStaffName);
        channelWorkOrderPicture.setUpdateTime(DateUtil.getNow());

        return updateSortByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer updateAuditFlagByKey(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.updateAuditFlagByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer updateAutoAuditFlagByKey(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.updateAutoAuditFlagByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer updateRequiredFlagByKey(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.updateRequiredFlagByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer updateByKey(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.updateByKey(channelWorkOrderPicture);
    }

    @Override
    public Integer insert(ChannelWorkOrderPicture channelWorkOrderPicture) {
        return channelWorkOrderPictureDao.insert(channelWorkOrderPicture);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return channelWorkOrderPictureDao.deleteByKey(id);
    }

    @Override
    public void copy(Integer originalChannelId, Integer targetChannelId, String operator) {

        channelWorkOrderPictureDao.copy(originalChannelId, targetChannelId, operator);
    }

    @Override
    public void deleteByChannelId(Integer channelId) {
        if (Objects.isNull(channelId)) {
            return;
        }
        channelWorkOrderPictureDao.deleteByChannelId(channelId);
    }
}